package com.ktjy.ruoyimes.pro.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ktjy.ruoyimes.pro.domain.ProProcess;
import com.ktjy.ruoyimes.pro.mapper.ProProcessContentMapper;
import com.ktjy.ruoyimes.pro.domain.ProProcessContent;
import com.ktjy.ruoyimes.pro.service.IProProcessContentService;

/**
 * 生产工序内容Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-09
 */
@Service
public class ProProcessContentServiceImpl implements IProProcessContentService 
{
    @Autowired
    private ProProcessContentMapper proProcessContentMapper;

    /**
     * 查询生产工序内容
     * 
     * @param contentId 生产工序内容主键
     * @return 生产工序内容
     */
    @Override
    public ProProcessContent selectProProcessContentByContentId(Long contentId)
    {
        return proProcessContentMapper.selectProProcessContentByContentId(contentId);
    }

    /**
     * 查询生产工序内容列表
     * 
     * @param proProcessContent 生产工序内容
     * @return 生产工序内容
     */
    @Override
    public List<ProProcessContent> selectProProcessContentList(ProProcessContent proProcessContent)
    {
        return proProcessContentMapper.selectProProcessContentList(proProcessContent);
    }

    /**
     * 新增生产工序内容
     * 
     * @param proProcessContent 生产工序内容
     * @return 结果
     */
    @Transactional
    @Override
    public int insertProProcessContent(ProProcessContent proProcessContent)
    {
        proProcessContent.setCreateTime(DateUtils.getNowDate());
        int rows = proProcessContentMapper.insertProProcessContent(proProcessContent);
        insertProProcess(proProcessContent);
        return rows;
    }

    /**
     * 修改生产工序内容
     * 
     * @param proProcessContent 生产工序内容
     * @return 结果
     */
    @Transactional
    @Override
    public int updateProProcessContent(ProProcessContent proProcessContent)
    {
        proProcessContent.setUpdateTime(DateUtils.getNowDate());
        proProcessContentMapper.deleteProProcessByProcessId(proProcessContent.getContentId());
        insertProProcess(proProcessContent);
        return proProcessContentMapper.updateProProcessContent(proProcessContent);
    }

    /**
     * 批量删除生产工序内容
     * 
     * @param contentIds 需要删除的生产工序内容主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteProProcessContentByContentIds(Long[] contentIds)
    {
        proProcessContentMapper.deleteProProcessByProcessIds(contentIds);
        return proProcessContentMapper.deleteProProcessContentByContentIds(contentIds);
    }

    /**
     * 删除生产工序内容信息
     * 
     * @param contentId 生产工序内容主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteProProcessContentByContentId(Long contentId)
    {
        proProcessContentMapper.deleteProProcessByProcessId(contentId);
        return proProcessContentMapper.deleteProProcessContentByContentId(contentId);
    }

    /**
     * 新增工序设置信息
     * 
     * @param proProcessContent 生产工序内容对象
     */
    public void insertProProcess(ProProcessContent proProcessContent)
    {
        List<ProProcess> proProcessList = proProcessContent.getProProcessList();
        Long contentId = proProcessContent.getContentId();
        if (StringUtils.isNotNull(proProcessList))
        {
            List<ProProcess> list = new ArrayList<ProProcess>();
            for (ProProcess proProcess : proProcessList)
            {
                proProcess.setProcessId(contentId);
                list.add(proProcess);
            }
            if (list.size() > 0)
            {
                proProcessContentMapper.batchProProcess(list);
            }
        }
    }
}
